/**
 * PlaylistController
 *
 * 主要职责：
 * - 歌单管理：创建/编辑歌单、给歌单添加/删除歌曲、分享、收藏
 *
 * 关键接口示例：
 * - Response createPlaylist(PlaylistDto dto)
 * - Response addSongToPlaylist(Long playlistId, Long songId)
 *
 * 依赖项：
 * - IPlaylistService
 *
 * 答辩要点：
 * - 并发编辑问题（乐观锁/悲观锁）、歌单与歌曲的多对多关系
 */
package net.zjitc.yqmusicserver.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import net.zjitc.yqmusicserver.domain.dto.PlaylistDTO;
import net.zjitc.yqmusicserver.domain.vo.PlaylistDetailVO;
import net.zjitc.yqmusicserver.domain.vo.PlaylistVO;
import net.zjitc.yqmusicserver.result.PageResult;
import net.zjitc.yqmusicserver.result.Result;
import net.zjitc.yqmusicserver.service.IPlaylistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/playlist")
public class PlaylistController {

    @Autowired
    private IPlaylistService playlistService;

    /**
     * 获取所有歌单
     *
     * @param playlistDTO playlistDTO
     * @return 歌单列表
     */
    @PostMapping("/getAllPlaylists")
    public Result<PageResult<PlaylistVO>> getAllPlaylists(@RequestBody @Valid PlaylistDTO playlistDTO) {
        return playlistService.getAllPlaylists(playlistDTO);
    }

    /**
     * 获取推荐歌单
     *
     * @param request request
     * @return 推荐歌单列表
     */
    @GetMapping("/getRecommendedPlaylists")
    public Result<List<PlaylistVO>> getRandomPlaylists(HttpServletRequest request) {
        return playlistService.getRecommendedPlaylists(request);
    }

    /**
     * 获取歌单详情
     *
     * @param playlistId 歌单id
     * @return 歌单详情
     */
    @GetMapping("/getPlaylistDetail/{id}")
    public Result<PlaylistDetailVO> getPlaylistDetail(@PathVariable("id") Long playlistId, HttpServletRequest request) {
        return playlistService.getPlaylistDetail(playlistId, request);
    }


}
